package cn.shengchao.rule.condition.matchType;

import cn.shengchao.rule.condition.valueType.IValueType;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @program: examstarapi
 * @description: 操作符=
 * @author: Xiong weiqiang
 * @create: 2025-04-11 14:32
 */
public class MatchTypeEquals implements IMatchType{
    @Override
    public String getMatchTypeKey() {
        return IMatchType.EQUALS;
    }

    @Override
    public String getMatchTypeValue() {
        return "等于";
    }

    @Override
    public boolean isMatch(String targetValue, String matchValue, IValueType valueType) {
        return switch (valueType.valueTypeKey()) {
            case IValueType.TYPE_INTEGER -> Long.parseLong(targetValue) == Long.parseLong(matchValue);
            case IValueType.TYPE_STRING, IValueType.TYPE_DATE, IValueType.TYPE_DAY -> targetValue.equals(matchValue);
            case IValueType.TYPE_DOUBLE -> Double.parseDouble(targetValue) == Double.parseDouble(matchValue);
            case IValueType.TYPE_ARRAY -> new HashSet<>(Arrays.asList(matchValue.split(","))).contains(targetValue);
            default -> false;
        };
    }


}